home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / oldwish / old / wishMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-10  |  19.4 KB  |  704 lines

  1. /* 
  2.  * fsflatMain.c --
  3.  *
  4.  *    Main routine for fsflat stuff.  Right now I'm just testing the
  5.  *    new scrollbar stuff.
  6.  *
  7.  * Copyright 1987 Regents of the University of California
  8.  * All rights reserved.
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: fsflatMain.c,v 1.1 88/10/03 12:48:21 mlgray Exp $ SPRITE (Berkeley)";
  20. #endif not lint
  21.  
  22. #include <X11/Xlib.h>
  23. #include <X11/Xutil.h>
  24. #define    Time    SpriteTime
  25. #include <sys/time.h>
  26. #include "string.h"
  27. #include <fs.h>
  28. #include "sx.h"
  29. #include "util.h"
  30. #include "monitorClient.h"
  31. #include "fsflatInt.h"
  32. #include <signal.h>
  33.  
  34. int    size;
  35.  
  36. /*
  37.  * The global table in which pointers to window information for each
  38.  * fsflat window is kept.
  39.  */
  40. XContext    fsflatWindowContext;
  41. XContext    fsflatGroupWindowContext;
  42.  
  43. /* Whether debugging is turned on or not */
  44. Boolean        fsflatDebugP = FALSE;
  45.  
  46. /* Whether the application should pick the initial window size */
  47. Boolean        fsflatPickSizeP = TRUE;
  48. /* whether the application can resize the window */
  49. Boolean        fsflatResizeP = FALSE;
  50. /* whether to display headers for groups with no files. */
  51. Boolean        fsflatShowEmptyGroupsP = FALSE;
  52. /* The display */
  53. Display        *fsflatDisplay;
  54.  
  55. /*
  56.  * The application name.
  57.  */
  58. char    *fsflatApplication = "fsflat";
  59.  
  60. /*
  61.  * For formulating error strings.  How big is big enough?
  62.  */
  63. char    fsflatErrorMsg[2 * MAXPATHLEN + 50];
  64.  
  65. /* Display info for calculating max size of windows */
  66. int        fsflatRootHeight;
  67. int        fsflatRootWidth;
  68.  
  69. /* Keep track of current directory. */
  70. char    fsflatCurrentDirectory[MAXPATHLEN + 1];
  71.  
  72. #ifdef ICON
  73. /*
  74.  * Icon window information.
  75.  */
  76.  
  77. #define ICONDIR    "/usr2/icon/X"
  78.  
  79. typedef struct {
  80.     int x;            /* Initial X, Y positions. */
  81.     int y;            
  82.     int width;
  83.     int height;
  84.     int foreground;        /* Foreground, background colors 
  85.                  * are same as the main window. */
  86.     int background;
  87.     char *name;            /* Filename of the icon bitmap file. */
  88.     Pixmap bitmap;        /* Bitmap data. */
  89.     Window window;        /* ID of the icon window. */
  90. } TxIconInfo;
  91. static TxIconInfo iconInfo = { 0, 0, 0, 0, 0, 0, NULL, NULL,};
  92. static void CreateIcon();
  93. #endif /* ICON */
  94.  
  95.  
  96. /*
  97.  *----------------------------------------------------------------------
  98.  *
  99.  * main --
  100.  *
  101.  *    Main routine for fsflat.
  102.  *
  103.  * Results:
  104.  *    None.
  105.  *
  106.  * Side effects:
  107.  *    Many.
  108.  *
  109.  *----------------------------------------------------------------------
  110.  */
  111. main(argc, argv)
  112.     int    argc;
  113.     char    *argv[];
  114. {
  115.     char    *string;
  116.     char    *geometry = NULL;    /* for window set-up */
  117.     char    *font;
  118.     FsflatWindow    *aWindow = NULL;
  119.     char    *startDir = NULL;
  120.     int        displayMask = 0;
  121.     int        numFDs;
  122. #ifdef NOTDEF
  123.     struct    timeval    alarm;
  124. #else /* NOTDEF */
  125.     SpriteTime    alarm;
  126. #endif /* NOTDEF */
  127.     int        monitorMask;
  128.     char    *cPtr;
  129.     extern    void    HandleMonitorEvent();
  130.     extern    void    FsflatDisplayEventProc();
  131.     extern    void    HandleMonitorStats();
  132.  
  133.     /*
  134.      * Process command line arguments.
  135.      */
  136.     while (argc > 1 ) { 
  137.     argc--;
  138.     argv++;
  139.     if (strcmp(argv[0], "-debug") == 0) {
  140.         fsflatDebugP = TRUE;
  141.         continue;
  142.     }
  143.     if (strcmp(argv[0], "-nopick") == 0) {
  144.         fsflatPickSizeP = FALSE;
  145.         continue;
  146.     }
  147.     if (strcmp(argv[0], "-resize") == 0) {
  148.         fsflatResizeP = TRUE;
  149.         continue;
  150.     }
  151.     if (strcmp(argv[0], "-empty") == 0) {
  152.         fsflatShowEmptyGroupsP = TRUE;
  153.         continue;
  154.     }
  155.     if (strcmp(argv[0], "-usage") == 0 ||
  156.         strcmp(argv[0], "-u") == 0) {
  157.         fprintf(stderr, "%s\n\n%s\n%s\n%s\n%s\n",
  158.             "fsflat -debug -nopick -resize -empty -usage dirname",
  159.             "-debug    Print debug messages and don't fork.",
  160.             "-nopick    Don't automatically pick initial window size.",
  161.             "-resize    Allow automatic resizing of window.",
  162.             "-empty    Display headers for groups without entries.");
  163.         exit(1);
  164.     }
  165.     startDir = argv[0];
  166.     }
  167.     /* Don't fork into background if debugging is on - so dbx works, etc. */
  168.     if (!fsflatDebugP) {
  169.     Proc_Detach(0);
  170.     }
  171.     /*
  172.      * Initialize the display and fsflatWindowContext and
  173.      * fsflatGroupWindowContext.
  174.      */
  175.     if ((fsflatDisplay = XOpenDisplay(NULL)) == NULL) {
  176.     fprintf(stderr, "Could not open display.\n");
  177.     exit(1);
  178.     }
  179.     if (fsflatDebugP) {
  180.     XSynchronize(fsflatDisplay, True);
  181.     }
  182.     Sx_SetErrorHandler();
  183.  
  184.     fsflatRootHeight = DisplayHeight(fsflatDisplay,
  185.         DefaultScreen(fsflatDisplay));
  186.     fsflatRootWidth = DisplayWidth(fsflatDisplay,
  187.         DefaultScreen(fsflatDisplay));
  188.  
  189.     /*
  190.      * 8 should be more than enough considering there's only 1 window
  191.      * right now!
  192.      */
  193.     fsflatWindowContext = XUniqueContext();
  194.     fsflatGroupWindowContext = XUniqueContext();
  195.  
  196.     /*
  197.      * Create a dummy structure for passing to FsflatCreate to create
  198.      * the first window and then process XDefault arguments.  
  199.      */
  200.     aWindow = (FsflatWindow *) malloc(sizeof (FsflatWindow));
  201.     
  202.     if (startDir != NULL) {
  203.     if (Util_CanonicalDir(startDir, NULL, aWindow->dir) == NULL) {
  204.         /* error message returned in aWindow->dir */
  205.         Sx_Panic(fsflatDisplay, aWindow->dir);
  206.     }
  207.     } else if (getwd(aWindow->dir) == NULL) {
  208.     sprintf(fsflatErrorMsg,
  209.         "%s: Couldn't get current working directory.\n",
  210.         fsflatApplication);
  211.     Sx_Panic(fsflatDisplay, fsflatErrorMsg);
  212.     }
  213.  
  214.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  215.         "Background")) != NULL) {
  216.     if ((aWindow->background =
  217.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  218.         aWindow->background = BlackPixel(fsflatDisplay,
  219.             DefaultScreen(fsflatDisplay));
  220.     }
  221.     } else {
  222.     aWindow->background = BlackPixel(fsflatDisplay,
  223.         DefaultScreen(fsflatDisplay));
  224.     }
  225.  
  226.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  227.         "Foreground")) != NULL) {
  228.     if ((aWindow->foreground =
  229.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  230.         /* Try to make it the opposite of the background */
  231.         if (aWindow->background == WhitePixel(fsflatDisplay,
  232.             DefaultScreen(fsflatDisplay))) {
  233.         aWindow->foreground = BlackPixel(fsflatDisplay,
  234.             DefaultScreen(fsflatDisplay));
  235.         } else {
  236.         aWindow->foreground = WhitePixel(fsflatDisplay,
  237.             DefaultScreen(fsflatDisplay));
  238.         }
  239.     }    
  240.     /* At least try to make it the opposite of the background */
  241.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  242.         DefaultScreen(fsflatDisplay))) {
  243.     aWindow->foreground = BlackPixel(fsflatDisplay,
  244.         DefaultScreen(fsflatDisplay));
  245.     } else {
  246.     aWindow->foreground = WhitePixel(fsflatDisplay,
  247.         DefaultScreen(fsflatDisplay));
  248.     }
  249.  
  250.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "Border"))
  251.         != NULL) {
  252.     if ((aWindow->border =
  253.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  254.         /* Try to make it the opposite of the background */
  255.         if (aWindow->background == WhitePixel(fsflatDisplay,
  256.             DefaultScreen(fsflatDisplay))) {
  257.         aWindow->border = BlackPixel(fsflatDisplay,
  258.             DefaultScreen(fsflatDisplay));
  259.         } else {
  260.         aWindow->border = WhitePixel(fsflatDisplay,
  261.             DefaultScreen(fsflatDisplay));
  262.         }
  263.     }
  264.     /* At least try to make it the opposite of the background */
  265.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  266.         DefaultScreen(fsflatDisplay))) {
  267.     aWindow->border = BlackPixel(fsflatDisplay,
  268.         DefaultScreen(fsflatDisplay));
  269.     } else {
  270.     aWindow->border = WhitePixel(fsflatDisplay,
  271.         DefaultScreen(fsflatDisplay));
  272.     }
  273.  
  274.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "Selection"))
  275.         != NULL) {
  276.     if ((aWindow->selection =
  277.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  278.         /* Try to make it the opposite of the background */
  279.         if (aWindow->background == WhitePixel(fsflatDisplay,
  280.             DefaultScreen(fsflatDisplay))) {
  281.         aWindow->selection = BlackPixel(fsflatDisplay,
  282.             DefaultScreen(fsflatDisplay));
  283.         } else {
  284.         aWindow->selection = WhitePixel(fsflatDisplay,
  285.             DefaultScreen(fsflatDisplay));
  286.         }
  287.     }    
  288.     /* At least try to make it the opposite of the background */
  289.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  290.         DefaultScreen(fsflatDisplay))) {
  291.     aWindow->selection = BlackPixel(fsflatDisplay,
  292.         DefaultScreen(fsflatDisplay));
  293.     } else {
  294.     aWindow->selection = WhitePixel(fsflatDisplay,
  295.         DefaultScreen(fsflatDisplay));
  296.     }
  297.  
  298.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  299.         "TitleBackground")) != NULL) {
  300.     if ((aWindow->titleBackground =
  301.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  302.         aWindow->titleBackground = aWindow->background;
  303.     }
  304.     } else {
  305.     aWindow->titleBackground = aWindow->background;
  306.     }
  307.  
  308.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  309.         "TxBackground")) != NULL) {
  310.     if ((aWindow->txBackground =
  311.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  312.         aWindow->txBackground = aWindow->background;
  313.     }
  314.     } else {
  315.     aWindow->txBackground = aWindow->background;
  316.     }
  317.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  318.         "MenuBackground")) != NULL) {
  319.     if ((aWindow->menuBackground =
  320.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  321.         aWindow->menuBackground = aWindow->background;
  322.     }
  323.     } else {
  324.     aWindow->menuBackground = aWindow->background;
  325.     }
  326.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  327.         "SortBackground")) != NULL) {
  328.     if ((aWindow->sortBackground =
  329.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  330.         aWindow->sortBackground = aWindow->background;
  331.     }
  332.     } else {
  333.     aWindow->sortBackground = aWindow->background;
  334.     }
  335.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  336.         "FieldsBackground")) != NULL) {
  337.     if ((aWindow->fieldsBackground =
  338.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  339.         aWindow->fieldsBackground = aWindow->background;
  340.     }
  341.     } else {
  342.     aWindow->fieldsBackground = aWindow->background;
  343.     }
  344.  
  345.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  346.         "EntryBackground")) != NULL) {
  347.     if ((aWindow->entryBackground =
  348.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  349.         aWindow->entryBackground = aWindow->background;
  350.     }
  351.     } else {
  352.     aWindow->entryBackground = aWindow->background;
  353.     }
  354.  
  355.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  356.         "ScrollBackground")) != NULL) {
  357.     if ((aWindow->scrollBackground =
  358.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  359.         aWindow->scrollBackground = aWindow->background;
  360.     }
  361.     } else {
  362.     aWindow->scrollBackground = aWindow->background;
  363.     }
  364.  
  365.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  366.         "TitleForeground")) != NULL) {
  367.     if ((aWindow->titleForeground =
  368.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  369.         aWindow->titleForeground = aWindow->foreground;
  370.     }    
  371.     } else {
  372.     aWindow->titleForeground = aWindow->foreground;
  373.     }
  374.  
  375.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  376.         "TxForeground")) != NULL) {
  377.     if ((aWindow->txForeground =
  378.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  379.         aWindow->txForeground = aWindow->foreground;
  380.     }    
  381.     } else {
  382.     aWindow->txForeground = aWindow->foreground;
  383.     }
  384.  
  385.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  386.         "MenuForeground")) != NULL) {
  387.     if ((aWindow->menuForeground =
  388.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  389.         aWindow->menuForeground = aWindow->foreground;
  390.     }
  391.     } else {
  392.     aWindow->menuForeground = aWindow->foreground;
  393.     }
  394.  
  395.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  396.         "SortForeground")) != NULL) {
  397.     if ((aWindow->sortForeground =
  398.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  399.         aWindow->sortForeground = aWindow->foreground;
  400.     }    
  401.     } else {
  402.     aWindow->sortForeground = aWindow->foreground;
  403.     }
  404.  
  405.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  406.         "FieldsForeground")) != NULL) {
  407.     if ((aWindow->fieldsForeground =
  408.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  409.         aWindow->fieldsForeground = aWindow->foreground;
  410.     }    
  411.     } else {
  412.     aWindow->fieldsForeground = aWindow->foreground;
  413.     }
  414.  
  415.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  416.         "EntryForeground")) != NULL) {
  417.     if ((aWindow->entryForeground =
  418.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  419.         aWindow->entryForeground = aWindow->foreground;
  420.     }    
  421.     } else {
  422.     aWindow->entryForeground = aWindow->foreground;
  423.     }
  424.  
  425.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  426.         "ScrollForeground")) != NULL) {
  427.     if ((aWindow->scrollForeground =
  428.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  429.         aWindow->scrollForeground = aWindow->foreground;
  430.     }    
  431.     } else {
  432.     aWindow->scrollForeground = aWindow->foreground;
  433.     }
  434.  
  435.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  436.         "BorderWidth")) != NULL) {
  437.     if ((aWindow->borderWidth = strtol(string, &cPtr, 10)) == 0 &&
  438.         cPtr == string) {
  439.         /* AtoI failed */
  440.         aWindow->borderWidth = 2;
  441.     }
  442.     } else {
  443.     aWindow->borderWidth = 2;
  444.     }
  445.  
  446.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  447.         "TitleBorder")) != NULL) {
  448.     if ((aWindow->titleBorder =
  449.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  450.         aWindow->titleBorder = aWindow->border;
  451.     }
  452.     } else {
  453.     aWindow->titleBorder = aWindow->border;
  454.     }
  455.  
  456.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "TxBorder"))
  457.         != NULL) {
  458.     if ((aWindow->txBorder =
  459.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  460.         aWindow->txBorder = aWindow->border;
  461.     }
  462.     } else {
  463.     aWindow->txBorder = aWindow->border;
  464.     }
  465.  
  466.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  467.         "ScrollElevator")) != NULL) {
  468.     if ((aWindow->scrollElevator =
  469.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  470.         aWindow->scrollElevator = aWindow->scrollForeground;
  471.     }    
  472.     } else {
  473.     aWindow->scrollElevator = aWindow->scrollForeground;
  474.     }
  475.  
  476.     if ((geometry = XGetDefault(fsflatDisplay, fsflatApplication, "Geometry"))
  477.         == NULL) {
  478.     geometry = "=550x350+160+160";
  479.     }
  480.     aWindow->geometry = geometry;
  481.  
  482.     if ((font = XGetDefault(fsflatDisplay, fsflatApplication, "Font"))
  483.         != NULL) {
  484.     aWindow->fontPtr = XLoadQueryFont(fsflatDisplay, font);
  485.     if (aWindow->fontPtr != NULL) {
  486.         Sx_SetDefaultFont(aWindow->fontPtr);
  487.     } else {
  488.         aWindow->fontPtr = Sx_GetDefaultFont(fsflatDisplay);
  489.     }
  490.     } else {
  491.     aWindow->fontPtr = Sx_GetDefaultFont(fsflatDisplay);
  492.     }
  493.  
  494.     if ((font = XGetDefault(fsflatDisplay, fsflatApplication, "TitleFont"))
  495.         != NULL) {
  496.     aWindow->titleFontPtr = XLoadQueryFont(fsflatDisplay, font);
  497.     if (aWindow->titleFontPtr != NULL) {
  498.         Sx_SetDefaultFont(aWindow->titleFontPtr);
  499.     }
  500.     }
  501.     if (aWindow->titleFontPtr == NULL) {
  502.     aWindow->titleFontPtr = Sx_GetDefaultFont(fsflatDisplay);
  503.     }
  504.  
  505.     aWindow->interp = NULL;
  506.  
  507.     if (!MonClient_Register()) {
  508.     Sx_Panic(fsflatDisplay,
  509.         "Initialization of file system monitor failed.");
  510.     }
  511.  
  512.     /* create the first window */
  513.     if (startDir != NULL) {
  514.     if (FsflatCreate(aWindow, startDir) == NULL) {
  515.         Sx_Panic(fsflatDisplay, "Couldn't create flat display window.");
  516.     }
  517.     } else {
  518.     if (FsflatCreate(aWindow, NULL) == NULL) {
  519.         Sx_Panic(fsflatDisplay, "Couldn't create flat display window.");
  520.     }
  521.     }
  522.     free(aWindow);        /* free dummy structure */
  523.  
  524. #ifdef ICON
  525.     /*
  526.      * Create the icon for the window. This must done after the
  527.      * main window is initialized.
  528.      */
  529.  
  530.     CreateIcon(display, window, info.foreground, info.background);
  531. #endif /* ICON */
  532.  
  533.     alarm.seconds = 5;
  534.     alarm.microseconds = 0;
  535.     Fs_EventHandlerCreate(monClient_ReadPort, FS_READABLE,
  536.         HandleMonitorEvent, NULL);
  537.     Fs_EventHandlerCreate(ConnectionNumber(fsflatDisplay), FS_READABLE,
  538.         FsflatDisplayEventProc, NULL);
  539.     Fs_TimeoutHandlerCreate(alarm, TRUE, HandleMonitorStats,
  540.         (ClientData) NULL);
  541.     while (fsflatWindowCount > 0) {
  542.     while ((size = QLength(fsflatDisplay)) > 0) {
  543.         XEvent    event;
  544.  
  545.         XNextEvent(fsflatDisplay, &event);
  546.         Sx_HandleEvent(&event);
  547.     }
  548.     Tx_FlushStreams();
  549.     Tx_Update();
  550.     Mx_Update();
  551.     if ((size = QLength(fsflatDisplay)) > 0) {
  552.         continue;
  553.     }
  554.     XFlush(fsflatDisplay);
  555.     Fs_Dispatch();
  556.     }
  557.  
  558. # ifdef NOTDEF
  559. /*
  560.  * Can't do this yet.  I don't know what I'll do about the utmp
  561.  * stuff for now.
  562.  */
  563.     if (txRegisterPty) {
  564.     char    *ptyName;
  565.    
  566.     if ((ptyName = TxWindowToPtyName(window)) != NULL) {
  567.         (void) TxUtmpEntry(FALSE, ptyName, (char *) NULL);
  568.     }
  569.     }
  570. # endif /* NOTDEF */
  571.     exit(0);
  572. }
  573.  
  574.  
  575. void
  576. FsflatDisplayEventProc(clientData, streamID, eventMask)
  577.     ClientData    clientData;
  578.     int        streamID;
  579.     int        eventMask;
  580. {
  581.     static    int    count = 0;
  582.     XEvent    event;
  583.  
  584.     do {
  585.     count++;
  586.     XNextEvent(fsflatDisplay, &event);
  587.     Sx_HandleEvent(&event);
  588.     } while (QLength(fsflatDisplay) > 0);
  589.  
  590.     return;
  591. }
  592.  
  593. void
  594. HandleMonitorStats(clientData, time)
  595.     ClientData    clientData;
  596.     SpriteTime    time;
  597. {
  598.     Mon_StatDirs();
  599.     return;
  600. }
  601.  
  602. void
  603. HandleMonitorEvent(clientData, streamID, eventMask)
  604.     ClientData    clientData;
  605.     int        streamID;
  606.     int        eventMask;
  607. {
  608.     FsflatHandleMonitorUpdates();
  609.     return;
  610. }
  611.  
  612. #ifdef ICON
  613.  
  614. /*
  615.  *----------------------------------------------------------------------
  616.  *
  617.  * CreateIcon --
  618.  *
  619.  *    This procedure creates an icon window for the main window 
  620.  *    using data read in from a X bitmap file.
  621.  *
  622.  *    If the icon file name is "localhost", the hostname of the machine
  623.  *    is used to locate an icon file for the host in a standard directory.
  624.  *
  625.  * Results:
  626.  *    None.
  627.  *
  628.  * Side effects:
  629.  *    An icon window is created.
  630.  *
  631.  *----------------------------------------------------------------------
  632.  */
  633.  
  634. static void
  635. CreateIcon(display, window, foreground, background)
  636.     Display    *display;
  637.     Window window;        /* An icon will be created for this window. */
  638.     unsigned long foreground;    /* Foreground color of the icon. */
  639.     unsigned long background;    /* Background color of the icon. */
  640. {
  641.     char iconfile[256];        /* Buffer to hold a complete icon file name. */
  642.     char hostname[100];        /* Buffer to hold the hostname. */
  643.     char *dot;
  644.     int status;
  645.     XWMHints hints;
  646.  
  647.     /*
  648.      * See if a icon file name was given on the command line or is in the
  649.      * .Xdefaults file.
  650.      */
  651.     if (iconInfo.name == (char *) NULL) {
  652.     iconInfo.name = XGetDefault(display, "tx", "icon");
  653.     if (iconInfo.name == (char *) NULL) {
  654.         return;
  655.     }
  656.     }
  657.  
  658.     /*
  659.      * If the file name is localhost, look in a standard directory for
  660.      * a file named after the host.
  661.      */
  662.     if (strcmp(iconInfo.name, "localhost") == 0) {
  663.     gethostname(hostname, sizeof(hostname));
  664.     dot = strchr(hostname, '.');
  665.     if (dot != (char *) NULL) {
  666.         *dot = '\0';
  667.     }
  668.     sprintf(iconfile, "%s/%s", ICONDIR, hostname);
  669.     iconInfo.name = iconfile;
  670.     }
  671.  
  672.     status = XReadBitmapFile(display, window, iconInfo.name, &iconInfo.width,
  673.         &iconInfo.height, &iconInfo.bitmap, 0, 0);
  674.  
  675.     if (status == 0) {
  676.     fprintf(stderr,
  677.         "Tx: can't open icon file %s, using default icon.\n", 
  678.         iconInfo.name);
  679.     return;
  680.     } else if (status < 0) {
  681.     fprintf(stderr, 
  682.         "Tx: icon file %s has invalid format.\n", iconInfo.name);
  683.     return;
  684.     }
  685.  
  686.     hints.flags = InputHint|StateHint|IconWindowHint
  687.         |IconPixmapHint|IconPositionHint;
  688.     hints.input = False;
  689.     hints.icon_pixmap = iconInfo.bitmap;
  690.     hints.icon_window = XCreateSimpleWindow(display,
  691.         RootWindow(display, DefaultScreen(display)),
  692.         iconInfo.x, iconInfo.y, iconInfo.width, iconInfo.height,
  693.         0, foreground, background);
  694.     hints.icon_x = iconInfo.x;
  695.     hints.icon_y = iconInfo.y;
  696.     XSetWMHints(display, window, &hints);
  697.  
  698. #ifdef notdef    /* Shouldn't be needed under X11. */
  699.     (void) Sx_HandlerCreate(display, iconInfo.window, ExposureMask,
  700.         RefreshIcon, (ClientData) 0);
  701. #endif
  702. }
  703. #endif /* ICON */
  704.